package net.hn.hnms.biz.plan.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.hn.hnms.biz.plan.domain.PlanDrivage;
import net.hn.hnms.biz.plan.vo.MonthOuputVO;
import net.hn.hnms.biz.plan.vo.PlanDrivageVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

public interface PlanDrivageMapper extends BaseMapper<PlanDrivage> {


    @Select("<script>" +
            "  select case when count(drivage_plan_id)>0 then count(drivage_plan_id)   else null end  as totalPlan, " +
            "  sum(drivage_plan_footage) as totalDrivagePlanFootage, " +
            "  min(plan_start_date) as planStartDate, " +
            "  max(plan_end_date) as planEndDate " +
            "  from plan_drivage where del_flag ='0' and  mine_code = #{mineCode} " +
            "</script>")
    PlanDrivageVO selectDrivageTotalByMineCode(@Param("mineCode") String mineCode);

    @Select("<script>" +
            "  select case when count(drivage_plan_id)>0 then count(drivage_plan_id)   else null end  as totalPlan, " +
            "  sum(drivage_plan_footage) as totalDrivagePlanFootage, " +
            "  min(plan_start_date) as planStartDate, " +
            "  max(plan_end_date) as planEndDate " +
            "  from plan_drivage where del_flag ='0' and  company_code = #{mineCode} " +
            "</script>")
    PlanDrivageVO selectDrivageTotalByCompanyCodeOrName(@Param("mineCode") String mineCode);

    @Select("<script>" +
            " select mining_plan_footage as miningPlanFootage from plan_mining pm where del_flag='0' and  " +
            "  pm.mining_plan_type='1' and mining_face_id =#{faceId} and  plan_start_date <![CDATA[ = ]]> to_date( #{weekTimeStart}, 'YYYY-MM-DD' ) and plan_end_date <![CDATA[ = ]]> to_date( #{weekTimeEnd}, 'YYYY-MM-DD' )   " +
            "</script>")
    PlanDrivageVO selectDrivagePlanFootageByMineCode(@Param("faceId") String faceId, @Param("weekTimeStart") String weekTimeStart, @Param("weekTimeEnd") String weekTimeEnd);


    List<MonthOuputVO> planMonthfootage(@Param("beginDate") Date beginDate, @Param("endDate") Date endDate, @Param("mineCode") String mineCode);
}
